/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.ActionEvent
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.TextField
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.scene.text.Text
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.baseSetting.saleSchedule;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.business.ProductSortSettingUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.plugIn.searchTextField.SearchTextField;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.baseSetting.saleSchedule.ProductSortSettingController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.productSortSetting.GetAddProductSortData;
import com.gys.data.productSortSetting.GetProductDetailOutData;
import com.gys.data.productSortSetting.GetProductSortOutData;
import com.gys.data.productSortSetting.GetQueryProVoOutData;
import com.gys.view.productSort.AddProductSortView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddProductSortController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(AddProductSortController.class);
    @FXML
    private SearchTextField addGspgProId;
    @FXML
    private TextField addGspgId;
    @FXML
    private TextField addGspgProName;
    @FXML
    private AnchorPane pane;
    @FXML
    private TextField addGspgName;
    @FXML
    private Text title;
    @FXML
    private TextField addGspgSpecs;
    @FXML
    private TableView<GetAddProductSortData> tableView;
    @FXML
    private TableColumn<GetAddProductSortData, String> specs;
    @FXML
    private TableColumn<GetAddProductSortData, String> proCode;
    @FXML
    private TableColumn<GetAddProductSortData, String> index;
    @FXML
    private TableColumn<GetAddProductSortData, String> proName;
    private ObservableList<GetAddProductSortData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    @Autowired
    private ProductSortSettingController productSortSettingController;
    private String proCodeSelect = "";
    Set<String> proIdsSet = new HashSet<String>();
    private String titleTemp = "";
    public boolean type;
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.addGspgProId.setTextFieldPrefWeight(150.0);
        this.addGspgProId.setTextFieldPrefHeight(30.0);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.proCodeSelect = "";
        this.title.setText(this.titleTemp);
        this.addGspgProId.setText(null);
        this.addGspgId.clear();
        this.addGspgProName.clear();
        this.addGspgName.clear();
        this.addGspgSpecs.clear();
        this.proIdsSet = new HashSet<String>();
        this.tableView.getItems().clear();
        this.tableView.refresh();
        if (this.type) {
            this.addGspgId.setDisable(false);
            this.addGspgName.setDisable(false);
        } else {
            this.addGspgId.setDisable(true);
            this.addGspgName.setDisable(true);
        }
        this.index.setCellValueFactory((Callback)new PropertyValueFactory(this.index.getId()));
        this.proCode.setCellValueFactory((Callback)new PropertyValueFactory(this.proCode.getId()));
        this.proName.setCellValueFactory((Callback)new PropertyValueFactory(this.proName.getId()));
        this.specs.setCellValueFactory((Callback)new PropertyValueFactory(this.specs.getId()));
        ArrayList<TextField> textFieldForm = new ArrayList<TextField>();
        textFieldForm.add(this.addGspgProName);
        textFieldForm.add(this.addGspgSpecs);
        this.addGspgProId.reLoadTextField(this.productSortSettingController.words, this.productSortSettingController.otherMap, textFieldForm);
        this.addGspgProName.clear();
        this.addGspgProName.textProperty().addListener((observable, oldValue, newValue) -> {
            if (ObjectUtil.isNotEmpty(newValue) && !this.proCodeSelect.equals(this.addGspgProId.getText())) {
                this.addPro();
            }
            this.addGspgProName.clear();
        });
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                AddProductSortView view = SpringUtil.getBean(AddProductSortView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.DELETE) {
                            GetAddProductSortData data = (GetAddProductSortData)AddProductSortController.this.tableView.getSelectionModel().getSelectedItem();
                            AddProductSortController.this.tableView.getItems().remove(data);
                            for (int i = 0; i < AddProductSortController.this.tableView.getItems().size(); ++i) {
                                ((GetAddProductSortData)AddProductSortController.this.tableView.getItems().get(i)).setIndex(String.valueOf(i + 1));
                            }
                            AddProductSortController.this.proIdsSet.remove(data.getProCode());
                            AddProductSortController.this.tableView.refresh();
                        }
                        e.consume();
                    }
                });
            }
        }, 1000L);
        if (!this.type) {
            this.initTableByEdit();
        }
    }

    private void initTableByEdit() {
        GetProductSortOutData productSortOutData = this.productSortSettingController.selectProSort;
        this.addGspgId.setText(productSortOutData.getGspgIdSort());
        this.addGspgName.setText(productSortOutData.getGspgNameSort());
        ObservableList<GetProductDetailOutData> detailOutData = this.productSortSettingController.getDetailInfo().getItems();
        ArrayList addProductSortDataList = new ArrayList();
        detailOutData.forEach(item -> {
            GetAddProductSortData addProductSortData1 = new GetAddProductSortData();
            addProductSortData1.setIndex(item.getIndexDetail().toString());
            addProductSortData1.setProCode(item.getGspgProId());
            addProductSortData1.setProName(item.getGspgProName());
            addProductSortData1.setSpecs(item.getGspgSpecs());
            addProductSortDataList.add(addProductSortData1);
            this.proIdsSet.add(item.getGspgProId());
        });
        this.observableTableList = FXCollections.observableArrayList(addProductSortDataList);
        this.tableView.setItems(this.observableTableList);
        this.tableView.refresh();
    }

    private void addPro() {
        if (!this.proIdsSet.add(this.addGspgProId.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8be5\u5546\u54c1\u5df2\u5b58\u5728");
            alert.show();
            this.addGspgProName.clear();
            this.proCodeSelect = "";
            return;
        }
        GetQueryProVoOutData proVoOutData = (GetQueryProVoOutData)this.productSortSettingController.otherMap.get(this.addGspgProId.getText());
        GetAddProductSortData addProductSortData = new GetAddProductSortData();
        addProductSortData.setProCode(proVoOutData.getProCode());
        addProductSortData.setProName(proVoOutData.getAddGspgProName());
        addProductSortData.setSpecs(proVoOutData.getAddGspgSpecs());
        addProductSortData.setIndex(this.tableView.getItems().size() + 1 + "");
        this.tableView.getItems().add(addProductSortData);
        this.tableView.refresh();
        this.proCodeSelect = this.addGspgProId.getText();
        this.addGspgProName.clear();
    }

    /*
     * Enabled aggressive block sorting
     */
    @FXML
    private void saveAction(ActionEvent event) {
        if (!this.addSaveCheck()) {
            return;
        }
        if (this.type) {
            HashMap<String, Object> param = new HashMap<String, Object>();
            param.put("gspgId", this.addGspgId.getText());
            param.put("gspgName", this.addGspgName.getText());
            param.put("proTableOutDataList", this.tableView.getItems());
            HttpJson httpJson = ProductSortSettingUtil.add(param);
            if (!httpJson.isSuccess()) {
                Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
                alert.showAndWait();
                return;
            }
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4fdd\u5b58\u6210\u529f");
            alert.showAndWait();
            this.productSortSettingController.initSortTableView();
        } else {
            HashMap<String, Object> param = new HashMap<String, Object>();
            param.put("gspgId", this.addGspgId.getText());
            param.put("gspgName", this.addGspgName.getText());
            param.put("proTableOutDataList", this.tableView.getItems());
            HttpJson httpJson = ProductSortSettingUtil.update(param);
            if (!httpJson.isSuccess()) {
                Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
                alert.showAndWait();
                return;
            }
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4fdd\u5b58\u6210\u529f");
            alert.showAndWait();
            this.productSortSettingController.initSortTableView();
        }
        this.closeAction();
    }

    public boolean addSaveCheck() {
        if (ObjectUtil.isEmpty(this.addGspgName.getText()) || ObjectUtil.isEmpty(this.addGspgId.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5206\u7c7b\u7f16\u7801\u4e0e\u5206\u7c7b\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return false;
        }
        if (this.addGspgName.getText().length() > 20) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5206\u7c7b\u540d\u79f0\u957f\u5ea6\u6700\u592720");
            alert.showAndWait();
            return false;
        }
        if (this.addGspgId.getText().length() > 10) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5206\u7c7b\u7f16\u7801\u957f\u5ea6\u6700\u592710");
            alert.showAndWait();
            return false;
        }
        if (this.tableView.getItems().size() == 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u9009\u62e9\u5546\u54c1");
            alert.showAndWait();
            return false;
        }
        return true;
    }

    @FXML
    private void closeAction() {
        this.pane.getScene().getWindow().hide();
    }

    public SearchTextField getAddGspgProId() {
        return this.addGspgProId;
    }

    public TextField getAddGspgId() {
        return this.addGspgId;
    }

    public TextField getAddGspgProName() {
        return this.addGspgProName;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public TextField getAddGspgName() {
        return this.addGspgName;
    }

    public Text getTitle() {
        return this.title;
    }

    public TextField getAddGspgSpecs() {
        return this.addGspgSpecs;
    }

    public TableView<GetAddProductSortData> getTableView() {
        return this.tableView;
    }

    public TableColumn<GetAddProductSortData, String> getSpecs() {
        return this.specs;
    }

    public TableColumn<GetAddProductSortData, String> getProCode() {
        return this.proCode;
    }

    public TableColumn<GetAddProductSortData, String> getIndex() {
        return this.index;
    }

    public TableColumn<GetAddProductSortData, String> getProName() {
        return this.proName;
    }

    public ObservableList<GetAddProductSortData> getObservableTableList() {
        return this.observableTableList;
    }

    public ProductSortSettingController getProductSortSettingController() {
        return this.productSortSettingController;
    }

    public String getProCodeSelect() {
        return this.proCodeSelect;
    }

    public Set<String> getProIdsSet() {
        return this.proIdsSet;
    }

    public String getTitleTemp() {
        return this.titleTemp;
    }

    public boolean isType() {
        return this.type;
    }

    public Timer getTimer() {
        return this.timer;
    }

    public void setAddGspgProId(SearchTextField addGspgProId) {
        this.addGspgProId = addGspgProId;
    }

    public void setAddGspgId(TextField addGspgId) {
        this.addGspgId = addGspgId;
    }

    public void setAddGspgProName(TextField addGspgProName) {
        this.addGspgProName = addGspgProName;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setAddGspgName(TextField addGspgName) {
        this.addGspgName = addGspgName;
    }

    public void setTitle(Text title) {
        this.title = title;
    }

    public void setAddGspgSpecs(TextField addGspgSpecs) {
        this.addGspgSpecs = addGspgSpecs;
    }

    public void setTableView(TableView<GetAddProductSortData> tableView) {
        this.tableView = tableView;
    }

    public void setSpecs(TableColumn<GetAddProductSortData, String> specs) {
        this.specs = specs;
    }

    public void setProCode(TableColumn<GetAddProductSortData, String> proCode) {
        this.proCode = proCode;
    }

    public void setIndex(TableColumn<GetAddProductSortData, String> index) {
        this.index = index;
    }

    public void setProName(TableColumn<GetAddProductSortData, String> proName) {
        this.proName = proName;
    }

    public void setObservableTableList(ObservableList<GetAddProductSortData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setProductSortSettingController(ProductSortSettingController productSortSettingController) {
        this.productSortSettingController = productSortSettingController;
    }

    public void setProCodeSelect(String proCodeSelect) {
        this.proCodeSelect = proCodeSelect;
    }

    public void setProIdsSet(Set<String> proIdsSet) {
        this.proIdsSet = proIdsSet;
    }

    public void setTitleTemp(String titleTemp) {
        this.titleTemp = titleTemp;
    }

    public void setType(boolean type) {
        this.type = type;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddProductSortController)) {
            return false;
        }
        AddProductSortController other = (AddProductSortController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        SearchTextField this$addGspgProId = this.getAddGspgProId();
        SearchTextField other$addGspgProId = other.getAddGspgProId();
        if (this$addGspgProId == null ? other$addGspgProId != null : !((this$addGspgProId)).equals(other$addGspgProId)) {
            return false;
        }
        TextField this$addGspgId = this.getAddGspgId();
        TextField other$addGspgId = other.getAddGspgId();
        if (this$addGspgId == null ? other$addGspgId != null : !this$addGspgId.equals(other$addGspgId)) {
            return false;
        }
        TextField this$addGspgProName = this.getAddGspgProName();
        TextField other$addGspgProName = other.getAddGspgProName();
        if (this$addGspgProName == null ? other$addGspgProName != null : !this$addGspgProName.equals(other$addGspgProName)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        TextField this$addGspgName = this.getAddGspgName();
        TextField other$addGspgName = other.getAddGspgName();
        if (this$addGspgName == null ? other$addGspgName != null : !this$addGspgName.equals(other$addGspgName)) {
            return false;
        }
        Text this$title = this.getTitle();
        Text other$title = other.getTitle();
        if (this$title == null ? other$title != null : !this$title.equals(other$title)) {
            return false;
        }
        TextField this$addGspgSpecs = this.getAddGspgSpecs();
        TextField other$addGspgSpecs = other.getAddGspgSpecs();
        if (this$addGspgSpecs == null ? other$addGspgSpecs != null : !this$addGspgSpecs.equals(other$addGspgSpecs)) {
            return false;
        }
        TableView<GetAddProductSortData> this$tableView = this.getTableView();
        TableView<GetAddProductSortData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<GetAddProductSortData, String> this$specs = this.getSpecs();
        TableColumn<GetAddProductSortData, String> other$specs = other.getSpecs();
        if (this$specs == null ? other$specs != null : !this$specs.equals(other$specs)) {
            return false;
        }
        TableColumn<GetAddProductSortData, String> this$proCode = this.getProCode();
        TableColumn<GetAddProductSortData, String> other$proCode = other.getProCode();
        if (this$proCode == null ? other$proCode != null : !this$proCode.equals(other$proCode)) {
            return false;
        }
        TableColumn<GetAddProductSortData, String> this$index = this.getIndex();
        TableColumn<GetAddProductSortData, String> other$index = other.getIndex();
        if (this$index == null ? other$index != null : !this$index.equals(other$index)) {
            return false;
        }
        TableColumn<GetAddProductSortData, String> this$proName = this.getProName();
        TableColumn<GetAddProductSortData, String> other$proName = other.getProName();
        if (this$proName == null ? other$proName != null : !this$proName.equals(other$proName)) {
            return false;
        }
        ObservableList<GetAddProductSortData> this$observableTableList = this.getObservableTableList();
        ObservableList<GetAddProductSortData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        ProductSortSettingController this$productSortSettingController = this.getProductSortSettingController();
        ProductSortSettingController other$productSortSettingController = other.getProductSortSettingController();
        if (this$productSortSettingController == null ? other$productSortSettingController != null : !(this$productSortSettingController).equals(other$productSortSettingController)) {
            return false;
        }
        String this$proCodeSelect = this.getProCodeSelect();
        String other$proCodeSelect = other.getProCodeSelect();
        if (this$proCodeSelect == null ? other$proCodeSelect != null : !this$proCodeSelect.equals(other$proCodeSelect)) {
            return false;
        }
        Set<String> this$proIdsSet = this.getProIdsSet();
        Set<String> other$proIdsSet = other.getProIdsSet();
        if (this$proIdsSet == null ? other$proIdsSet != null : !(this$proIdsSet).equals(other$proIdsSet)) {
            return false;
        }
        String this$titleTemp = this.getTitleTemp();
        String other$titleTemp = other.getTitleTemp();
        if (this$titleTemp == null ? other$titleTemp != null : !this$titleTemp.equals(other$titleTemp)) {
            return false;
        }
        if (this.isType() != other.isType()) {
            return false;
        }
        Timer this$timer = this.getTimer();
        Timer other$timer = other.getTimer();
        return !(this$timer == null ? other$timer != null : !this$timer.equals(other$timer));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddProductSortController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        SearchTextField $addGspgProId = this.getAddGspgProId();
        result = result * 59 + ($addGspgProId == null ? 43 : (($addGspgProId)).hashCode());
        TextField $addGspgId = this.getAddGspgId();
        result = result * 59 + ($addGspgId == null ? 43 : $addGspgId.hashCode());
        TextField $addGspgProName = this.getAddGspgProName();
        result = result * 59 + ($addGspgProName == null ? 43 : $addGspgProName.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        TextField $addGspgName = this.getAddGspgName();
        result = result * 59 + ($addGspgName == null ? 43 : $addGspgName.hashCode());
        Text $title = this.getTitle();
        result = result * 59 + ($title == null ? 43 : $title.hashCode());
        TextField $addGspgSpecs = this.getAddGspgSpecs();
        result = result * 59 + ($addGspgSpecs == null ? 43 : $addGspgSpecs.hashCode());
        TableView<GetAddProductSortData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<GetAddProductSortData, String> $specs = this.getSpecs();
        result = result * 59 + ($specs == null ? 43 : $specs.hashCode());
        TableColumn<GetAddProductSortData, String> $proCode = this.getProCode();
        result = result * 59 + ($proCode == null ? 43 : $proCode.hashCode());
        TableColumn<GetAddProductSortData, String> $index = this.getIndex();
        result = result * 59 + ($index == null ? 43 : $index.hashCode());
        TableColumn<GetAddProductSortData, String> $proName = this.getProName();
        result = result * 59 + ($proName == null ? 43 : $proName.hashCode());
        ObservableList<GetAddProductSortData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        ProductSortSettingController $productSortSettingController = this.getProductSortSettingController();
        result = result * 59 + ($productSortSettingController == null ? 43 : ($productSortSettingController).hashCode());
        String $proCodeSelect = this.getProCodeSelect();
        result = result * 59 + ($proCodeSelect == null ? 43 : $proCodeSelect.hashCode());
        Set<String> $proIdsSet = this.getProIdsSet();
        result = result * 59 + ($proIdsSet == null ? 43 : ($proIdsSet).hashCode());
        String $titleTemp = this.getTitleTemp();
        result = result * 59 + ($titleTemp == null ? 43 : $titleTemp.hashCode());
        result = result * 59 + (this.isType() ? 79 : 97);
        Timer $timer = this.getTimer();
        result = result * 59 + ($timer == null ? 43 : $timer.hashCode());
        return result;
    }

    public String toString() {
        return "AddProductSortController(addGspgProId=" + (this.getAddGspgProId()) + ", addGspgId=" + this.getAddGspgId() + ", addGspgProName=" + this.getAddGspgProName() + ", pane=" + this.getPane() + ", addGspgName=" + this.getAddGspgName() + ", title=" + this.getTitle() + ", addGspgSpecs=" + this.getAddGspgSpecs() + ", tableView=" + this.getTableView() + ", specs=" + this.getSpecs() + ", proCode=" + this.getProCode() + ", index=" + this.getIndex() + ", proName=" + this.getProName() + ", observableTableList=" + this.getObservableTableList() + ", productSortSettingController=" + this.getProductSortSettingController() + ", proCodeSelect=" + this.getProCodeSelect() + ", proIdsSet=" + this.getProIdsSet() + ", titleTemp=" + this.getTitleTemp() + ", type=" + this.isType() + ", timer=" + this.getTimer() + ")";
    }
}

